<?php
/**
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 *
 * This license is also available via the world-wide-web at
 * http://itdapps.ncsu.edu/bsd.txt
 *
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to itappdev@ncsu.edu so we can send you a copy immediately.
 *
 * @package    Feed_Controller
 * @category   Controller
 * @copyright  Copyright (c) 2007 NC State University Office of Information Technology
 * @license    http://itdapps.ncsu.edu/bsd.txt  BSD License
 * @version    SVN: $Id: $
 */

/**
 *
 * @package    Feed_Controller
 * @category   Controller
 * @copyright  Copyright (c) 2007 NC State University Office of Information Technology
 */
class FeedController extends Zend_Controller_Action 
{   
          
    public function indexAction()
    {    	
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNeverRender();	 
    	
    	$server = new Zend_Rest_Server();
		$server->setClass('Google_Events');
		$server->returnResponse(true);
		$responseXml = $server->handle();
		
		$get = Zend_Registry::get('getFilter');
		$params = $_GET;
		

		if (!array_key_exists('method', $params)) {
		    $this->_helper->redirector->gotoRoute(array('module' => 'default', 'controller' => 'documentation', 'action' => 'index'), 'default', true);
		}
		
		$format = 'xml';
		
		if (array_key_exists('format', $params)) {
		    
		    switch (strtolower($params->format)) {
		        case 'json' :
		            $format = 'json';
		            break;
		        
		        case 'xml' : 
		            $format = 'xml';
		            break;
		        
		        default: 
		            $format = 'xml';
		            break;
		    }
		}
		
		switch ($format) {
		    case 'json' :
		        header('Content-Type: application/json');
		        echo Zend_Json::fromXML($responseXml);
		        break;
		    
		    case 'xml' : 
		        header('Content-Type: text/xml');
		        echo $responseXml;
		        break; 
		}
    }
	
}

